#ifndef __Qbot_H
#define __Qbot_H

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "RTE_Components.h"
#include "stm32f10x.h"
#include "stm32f10x_it.h"
#include "Driver_USART.h"
#include "wingbot_usart.h"
#include "wingbot_timer.h"
#include "wingbot_tick.h"
#include "db_wdg.h"
#include "led.h"
#include "Stream.h"
#include "wingbot_can.h"
#include "simple_dataframe_slave.h"
#include "data_holder.h"
#include <string.h>
#include "RS485.h"
#include "Kinco.h"
#include "Briter.h"
#include "MySetting.h"
#include <Modbus.h>
#include <ModbusSerial.h>

class Qbot: public Notify{
    
    private:
        Simple_dataframe* frame;
        Data_holder* dh;
        MySetting* st;
        WheelState_T state;
        float vl_dire;
        float vr_dire;
    
    public:
        KincoMotor* motor[2];
        Briter* encoder;
        short wheel_vel;        //轮子的整体速度
        double encoder_total_turns;

    public:
        static Qbot* instance(){
            static Qbot qb;
            return &qb;
        }
        void setState(WheelState_T s)
        {
            state = s;
        }
        void main_loop(void);
        void ms10_loop(void);
        void ms100_loop(void);
        void modbus_serial_init(void);
        void modbus_serial_loop(void);
        void run_forever(void);
        void init(void);
        void updateVelocity(void);
        void updateVelocity(short vl, short vr);
        void getActualState(void);
        void updateEncoder(void);
        void updateConnectState(void);
        virtual void update(const MESSAGE_ID id, void* data);
        
    private:
        Qbot();
        float rpm2mps(short rpm);
        short mps2rpm(float mps);

};

#endif

/* EOF */
